using System;
using SmartMathLibrary;

namespace SmartMathLibrary.QuadPack
{
    /// <summary>
    /// DQAWF - Approximation to Fourier integral.
    /// </summary>
    [Serializable]
    public static class DqawfClass
    {
        /// <summary>
        /// Approximation to Fourier integral.
        /// </summary>
        /// <param name="f">Double precision function to be integrated.</param>
        /// <param name="a">The lower limit of integration.</param>
        /// <param name="omega">The omega parameter in weight function.</param>
        /// <param name="sincos">Indicates which weight function to use: sincos = COSINE (= 1) --- use cos(omega*x); sincos = SINE   (= 2) --- use sin(omega*x).</param>
        /// <param name="epsabs">The absolute accuracy requested.</param>
        /// <param name="abserr">The estimate of the modulus of the absolute error.</param>
        /// <param name="neval">The needed function evalations.</param>
        /// <param name="ier">The requested errorcode.</param>
        /// <returns>The approximation to Fourier integral.</returns>
        public static double Dqawf(HardRealFunction f, double a, double omega, int sincos, double epsabs,
                                   ref double abserr, ref int neval, ref int ier)
        {
            double[,] chebmo = new double[QuadPackConstants.MAXP1,QuadPackConstants.MAXP1];
            double[] erlst = new double[50];
            double[] rslst = new double[50];

            int[] ierlst = new int[50];

            ier = 6;
            neval = 0;
            double result = 0.0;
            abserr = 0.0;

            // Dimensioning parameters.
            // *	limlst - upper bound on number of cycles,	
            // *	MAXP1 - upper bound on the number of Chebyshev moments.
            // 
            int limlst = 50;

            // Check validity of limlst and MAXP1. 
            if ((limlst < 3) || (QuadPackConstants.MAXP1 < 1))
            {
                goto _10;
            }

            // Prepare call for dqawfe. 
            result = DqawfeClass.Dqawfe(f, a, omega, sincos, epsabs, limlst, QuadPackConstants.MAXP1, ref abserr,
                                        ref neval, ref ier, rslst, erlst, ierlst, chebmo);
            _10:


            return result;
        }
    }
}